/**
 * @ListTVLDemo.java  COPYRIGHT xiaojian
 * 
 * Created on 2018年4月24日 上午10:48:33
 */
package xj.toolkit.bean.tlv.test;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import xj.toolkit.bean.tlv.decode.decoders.BeanTLVDecoder;
import xj.toolkit.bean.tlv.encode.encoders.BeanTLVEncoder;
import xj.toolkit.util.ByteUtils;

/**
 * @author <a href="mailto:cxj2000@gmail.com">xiaojian.cao</a>
 *
 */
public class ListTVLDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
            	"xiaojian/toolkit/bean/tlv/test/tlvDemo3.xml");
		
		ListTLV tlv = new ListTLV();
		tlv.names.add("xiao");
		tlv.names.add("jiann");
		
		tlv.ages.add(1);
		tlv.ages.add(2);
		
		BeanTLVEncoder beanEncoder = (BeanTLVEncoder)ctx.getBean("beanEncoder");
		
		byte[]	bytes = ByteUtils.union(beanEncoder.encode(tlv, 
    			beanEncoder.getEncodeContextFactory().createEncodeContext(ListTLV.class, null)));
		
		System.out.println(ByteUtils.bytesAsHexString(bytes, 1024));
		
		BeanTLVDecoder beanDecoder = (BeanTLVDecoder)ctx.getBean(BeanTLVDecoder.class);
    	Object bean = beanDecoder.decode(bytes.length, bytes, 
    			beanDecoder.getDecodeContextFactory().createDecodeContext(ListTLV.class, null));
    	System.out.println( bean );
	}

}
